<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加管理员</title>
    <style type="text/css">
        #message{
            color: red;
        }
    </style>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.3.js"></script>
    <script>
        var userNameFlag;
        var passwordFlag;
        function toSubmit() {
            if (userNameFlag && passwordFlag) {
                var name = $("#userName").val();
                $.ajax({
                    type: "POST",
                    url: "/scvs/manager/check",
                    data: {userName: name},
                    dataType: "json",
                    success: function (data) {
                        console.log(data);
                        if (data) {
                            $("#managerForm").submit();
                        } else {
                            $("#message").text("用户名已存在");
                        }
                    }
                });
            } else {
                $("#message").text("还有信息未输入");
                return;
            }
        }
        function checkUserName(obj) {
            if (obj.value.trim() == "") {
                userNameFlag = false;
                $("#message").text("请输入用户名");
            } else {
                userNameFlag = true;
            }
        }
        function checkPassword(obj) {
            if (obj.value.trim() == "") {
                passwordFlag = false;
                $("#message").text("请输入密码");
            } else {
                passwordFlag = true;
            }
        }
    </script>
</head>
<body>
<%@include file="../common/headManager.jsp" %>
<form id="managerForm" action="/scvs/manager/add" method="post">
    <table align="center">
        <tr>
            <td>登录名</td>
            <td><input type="text" id="userName" name="manager.userName" onblur="checkUserName(this)"/></td>
        </tr>
        <tr>
            <td>姓名</td>
            <td><input type="text" name="manager.realName"/></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="text" name="manager.password" onblur="checkPassword(this)"/></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><span id="message"></span></td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" onclick="toSubmit()" value="提交"/></td>
        </tr>
    </table>
</form>
</body>
</html>
